package com.sojson.util.security.springsecurity;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;

import com.sojson.util.security.springsecurity.service.impl.CustomDaoAuthenticationProviderImpl;

/**
 * SpringSecurityWeb配置
 * 
 * @author liu
 * @date 2021-12-01
 */
@Configuration
public class SecurityHandlerWebConfig {

    /**
     * 用户验证处理
     * 
     * @param userDetailsService    获取用户逻辑
     * @param passwordEncoder       密码编辑器
     * @return
     */
    @Bean
    public DaoAuthenticationProvider daoAuthenticationProvider(UserDetailsService userDetailsService,
        PasswordEncoder passwordEncoder) {
        DaoAuthenticationProvider provider = new CustomDaoAuthenticationProviderImpl();
        // 设置获取用户逻辑
        provider.setUserDetailsService(userDetailsService);
        // 设置密码编辑器
        provider.setPasswordEncoder(passwordEncoder);
        // 设置是否隐藏找不到用户异常(这里隐藏掉,因为要用自己的异常)
        provider.setHideUserNotFoundExceptions(true);
        return provider;
    }

}